﻿using System.IO;
using WMFInterface;
using WMFWrapper;

namespace WMVStreamEditor
{
	/// <summary>
	/// Информация о источнике
	/// </summary>
	public class SourceInfo
	{
		public SourceInfo(string fileName)
		{
			using(var encoder = new AsfReader(fileName))
			{
				var profile = encoder.GetProfile();
				var streams = profile.Streams;
				var sifos = new StreamInfo[streams.Length];
				for (var i = 0; i < streams.Length; ++i)
				{
					sifos[i] = new StreamInfo(streams[i]);
				}
				streams_ = sifos;
				ScriptsCount = profile.ScriptsCount;
			}
			FullName = fileName;
			Name = Path.GetFileName(fileName);			
		}

		/// <summary>
		/// Имя файла
		/// </summary>
		public string Name { get; private set; }
		/// <summary>
		/// Путь к файлу
		/// </summary>
		public string FullName { get; private set; }
		/// <summary>
		/// Стримы файла
		/// </summary>
		public StreamInfo[] Streams
		{
			get { return (StreamInfo[])streams_.Clone(); }			
		}
		/// <summary>
		/// Число скриптов
		/// </summary>
		public int ScriptsCount { get; private set; }
		/// <summary>
		/// Флаг выбора скриптов
		/// </summary>
		public bool ScriptsActive { get; set; }

		private readonly StreamInfo[] streams_;
	}

	/// <summary>
	/// Информация о стриме
	/// </summary>
	public class StreamInfo
	{
		public StreamInfo(WMFInterface.Stream stream)
		{
			Stream = stream;
			Selected = false;
		}

		public StreamType Type
		{
			get
			{
				return Stream.Type;
			}
		}
		public bool Selected { get; set; }
		public uint BitRate
		{
			get
			{
				return Stream.BitRate;
			}
		}
		public int Number
		{
			get
			{
				return Stream.Number;
			}
		}
		public string Language
		{
			get
			{
				return Stream.Language;
			}
		}

		public WMFInterface.Stream Stream { get; private set; }
	}
}
